<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2020/6/11
 * Time: 10:23
 */

namespace app\applet\controller;


use app\share\model\Token;
use think\Validate;

class Shoppay
{

    public function __construct(){
        $this->ShopPay=new \app\applet\model\ShopPay();
        $this->token=new Token();
    }

    /*
     * 到店支付页面
     */
    public function index(){
        $input = input();
        $validate = new Validate([
            ['store_id', 'require', '店铺ID不能为空'],
        ]);
        if(!$validate->check($input))
        {
            returnJson(-2003,$validate->getError());
        }
        $input['member_id'] = get_header_id("token");

        $returnData=$this->ShopPay->getInfo($input);

        returnJson(200,'success',$returnData);
    }

    /**
     * 到店支付创建订单
     */

    public function createOrder(){
        $input = input();
        $validate = new Validate([
            ['store_id', 'require', '店铺ID不能为空'],
            ['pay_amount', 'require', '支付金额不能为空'],
            ['pay_method', 'require', '支付方式不能为空'],
        ]);
        if(!$validate->check($input))
        {
            returnJson(-2003,$validate->getError());
        }
        $input['member_id'] = get_header_id("token");

        $returnData=$this->ShopPay->createOrder($input);

        returnJson(200,'success',$returnData);
    }

    /**
     * 取消支付
     */
    public function cancelPay(){
        $input = input();
        $validate = new Validate([
            ['consume_sn', 'require', '支付单号不能为空'],

        ]);
        if(!$validate->check($input))
        {
            returnJson(-2003,$validate->getError());
        }
        $input['member_id']= get_header_id("token");

        $returnData=$this->ShopPay->cancelOrder($input);
        returnJson(200,'success',$returnData);

    }



}